﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Viet_Calculator
{
	/// <summary>
	/// Summary description for ChiaPhuongTrinhBac2ChoPhuongTrinhBac1.
	/// </summary>
	public class ChiaPhuongTrinhBac2ChoPhuongTrinhBac1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.TextBox txtKetQua;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox5;
		private System.Windows.Forms.Button btnChia;
		private System.Windows.Forms.TextBox txtBB;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox txtAA;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.Label label17;
		private System.Windows.Forms.TextBox txtC;
		private System.Windows.Forms.TextBox txtB;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtA;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox txtO8;
		private System.Windows.Forms.TextBox txtO7;
		private System.Windows.Forms.TextBox txtO6;
		private System.Windows.Forms.TextBox txtO5;
		private System.Windows.Forms.TextBox txtO4;
		private System.Windows.Forms.TextBox txtO3;
		private System.Windows.Forms.TextBox txtO2;
		private System.Windows.Forms.TextBox txtO1;
		private System.Windows.Forms.TextBox txtNghiemPTB1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ChiaPhuongTrinhBac2ChoPhuongTrinhBac1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ChiaPhuongTrinhBac2ChoPhuongTrinhBac1));
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.txtKetQua = new System.Windows.Forms.TextBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.groupBox5 = new System.Windows.Forms.GroupBox();
			this.btnChia = new System.Windows.Forms.Button();
			this.txtBB = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.txtAA = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label16 = new System.Windows.Forms.Label();
			this.label17 = new System.Windows.Forms.Label();
			this.txtC = new System.Windows.Forms.TextBox();
			this.txtB = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.txtA = new System.Windows.Forms.TextBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.label7 = new System.Windows.Forms.Label();
			this.txtO8 = new System.Windows.Forms.TextBox();
			this.txtO7 = new System.Windows.Forms.TextBox();
			this.txtO6 = new System.Windows.Forms.TextBox();
			this.txtO5 = new System.Windows.Forms.TextBox();
			this.txtO4 = new System.Windows.Forms.TextBox();
			this.txtO3 = new System.Windows.Forms.TextBox();
			this.txtO2 = new System.Windows.Forms.TextBox();
			this.txtO1 = new System.Windows.Forms.TextBox();
			this.txtNghiemPTB1 = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox4.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox5.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox4
			// 
			this.groupBox4.Controls.Add(this.txtKetQua);
			this.groupBox4.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox4.Location = new System.Drawing.Point(8, 376);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.Size = new System.Drawing.Size(584, 64);
			this.groupBox4.TabIndex = 7;
			this.groupBox4.TabStop = false;
			this.groupBox4.Text = "Kết quả";
			// 
			// txtKetQua
			// 
			this.txtKetQua.Location = new System.Drawing.Point(24, 24);
			this.txtKetQua.Name = "txtKetQua";
			this.txtKetQua.ReadOnly = true;
			this.txtKetQua.Size = new System.Drawing.Size(408, 22);
			this.txtKetQua.TabIndex = 0;
			this.txtKetQua.Text = "";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.groupBox5);
			this.groupBox2.Controls.Add(this.txtBB);
			this.groupBox2.Controls.Add(this.label4);
			this.groupBox2.Controls.Add(this.label6);
			this.groupBox2.Controls.Add(this.txtAA);
			this.groupBox2.Controls.Add(this.label3);
			this.groupBox2.Controls.Add(this.label16);
			this.groupBox2.Controls.Add(this.label17);
			this.groupBox2.Controls.Add(this.txtC);
			this.groupBox2.Controls.Add(this.txtB);
			this.groupBox2.Controls.Add(this.label2);
			this.groupBox2.Controls.Add(this.label5);
			this.groupBox2.Controls.Add(this.txtA);
			this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox2.Location = new System.Drawing.Point(8, 88);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(584, 120);
			this.groupBox2.TabIndex = 5;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Chia đa thức";
			// 
			// groupBox5
			// 
			this.groupBox5.Controls.Add(this.btnChia);
			this.groupBox5.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox5.Location = new System.Drawing.Point(464, 16);
			this.groupBox5.Name = "groupBox5";
			this.groupBox5.Size = new System.Drawing.Size(104, 88);
			this.groupBox5.TabIndex = 31;
			this.groupBox5.TabStop = false;
			// 
			// btnChia
			// 
			this.btnChia.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnChia.Location = new System.Drawing.Point(16, 32);
			this.btnChia.Name = "btnChia";
			this.btnChia.Size = new System.Drawing.Size(72, 24);
			this.btnChia.TabIndex = 0;
			this.btnChia.Text = "Chia";
			this.btnChia.Click += new EventHandler(btnChia_Click);
			// 
			// txtBB
			// 
			this.txtBB.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtBB.Location = new System.Drawing.Point(264, 80);
			this.txtBB.Name = "txtBB";
			this.txtBB.Size = new System.Drawing.Size(120, 22);
			this.txtBB.TabIndex = 30;
			this.txtBB.Text = "";
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(232, 80);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(16, 24);
			this.label4.TabIndex = 29;
			this.label4.Text = "+";
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label6.Location = new System.Drawing.Point(208, 80);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(16, 24);
			this.label6.TabIndex = 28;
			this.label6.Text = "x";
			// 
			// txtAA
			// 
			this.txtAA.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtAA.Location = new System.Drawing.Point(80, 80);
			this.txtAA.Name = "txtAA";
			this.txtAA.Size = new System.Drawing.Size(120, 22);
			this.txtAA.TabIndex = 27;
			this.txtAA.Text = "";
			this.txtAA.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 56);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(424, 16);
			this.label3.TabIndex = 26;
			this.label3.Text = "---------------------------------------------------------------------------------" +
				"-------------";
			// 
			// label16
			// 
			this.label16.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label16.Location = new System.Drawing.Point(312, 24);
			this.label16.Name = "label16";
			this.label16.Size = new System.Drawing.Size(16, 24);
			this.label16.TabIndex = 25;
			this.label16.Text = "+";
			// 
			// label17
			// 
			this.label17.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label17.Location = new System.Drawing.Point(280, 24);
			this.label17.Name = "label17";
			this.label17.Size = new System.Drawing.Size(16, 24);
			this.label17.TabIndex = 24;
			this.label17.Text = "x";
			// 
			// txtC
			// 
			this.txtC.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtC.Location = new System.Drawing.Point(344, 24);
			this.txtC.Name = "txtC";
			this.txtC.Size = new System.Drawing.Size(88, 22);
			this.txtC.TabIndex = 23;
			this.txtC.Text = "";
			this.txtC.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// txtB
			// 
			this.txtB.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtB.Location = new System.Drawing.Point(184, 24);
			this.txtB.Name = "txtB";
			this.txtB.Size = new System.Drawing.Size(88, 22);
			this.txtB.TabIndex = 20;
			this.txtB.Text = "";
			this.txtB.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(152, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(16, 24);
			this.label2.TabIndex = 19;
			this.label2.Text = "+";
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label5.Location = new System.Drawing.Point(120, 24);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(24, 24);
			this.label5.TabIndex = 18;
			this.label5.Text = "x2";
			// 
			// txtA
			// 
			this.txtA.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtA.Location = new System.Drawing.Point(24, 24);
			this.txtA.Name = "txtA";
			this.txtA.Size = new System.Drawing.Size(88, 22);
			this.txtA.TabIndex = 17;
			this.txtA.Text = "";
			this.txtA.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.label7);
			this.groupBox3.Controls.Add(this.txtO8);
			this.groupBox3.Controls.Add(this.txtO7);
			this.groupBox3.Controls.Add(this.txtO6);
			this.groupBox3.Controls.Add(this.txtO5);
			this.groupBox3.Controls.Add(this.txtO4);
			this.groupBox3.Controls.Add(this.txtO3);
			this.groupBox3.Controls.Add(this.txtO2);
			this.groupBox3.Controls.Add(this.txtO1);
			this.groupBox3.Controls.Add(this.txtNghiemPTB1);
			this.groupBox3.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox3.Location = new System.Drawing.Point(8, 216);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(584, 152);
			this.groupBox3.TabIndex = 6;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Xử lý dữ liệu";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(112, 88);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(336, 16);
			this.label7.TabIndex = 10;
			this.label7.Text = "--------------------------------------------------------------------------";
			// 
			// txtO8
			// 
			this.txtO8.Location = new System.Drawing.Point(336, 112);
			this.txtO8.Name = "txtO8";
			this.txtO8.ReadOnly = true;
			this.txtO8.Size = new System.Drawing.Size(96, 22);
			this.txtO8.TabIndex = 9;
			this.txtO8.Text = "";
			// 
			// txtO7
			// 
			this.txtO7.Location = new System.Drawing.Point(224, 112);
			this.txtO7.Name = "txtO7";
			this.txtO7.ReadOnly = true;
			this.txtO7.Size = new System.Drawing.Size(96, 22);
			this.txtO7.TabIndex = 8;
			this.txtO7.Text = "";
			// 
			// txtO6
			// 
			this.txtO6.Location = new System.Drawing.Point(112, 112);
			this.txtO6.Name = "txtO6";
			this.txtO6.ReadOnly = true;
			this.txtO6.Size = new System.Drawing.Size(96, 22);
			this.txtO6.TabIndex = 7;
			this.txtO6.Text = "";
			// 
			// txtO5
			// 
			this.txtO5.Location = new System.Drawing.Point(336, 56);
			this.txtO5.Name = "txtO5";
			this.txtO5.ReadOnly = true;
			this.txtO5.Size = new System.Drawing.Size(96, 22);
			this.txtO5.TabIndex = 6;
			this.txtO5.Text = "";
			// 
			// txtO4
			// 
			this.txtO4.Location = new System.Drawing.Point(224, 56);
			this.txtO4.Name = "txtO4";
			this.txtO4.ReadOnly = true;
			this.txtO4.Size = new System.Drawing.Size(96, 22);
			this.txtO4.TabIndex = 5;
			this.txtO4.Text = "";
			// 
			// txtO3
			// 
			this.txtO3.Location = new System.Drawing.Point(336, 24);
			this.txtO3.Name = "txtO3";
			this.txtO3.ReadOnly = true;
			this.txtO3.Size = new System.Drawing.Size(96, 22);
			this.txtO3.TabIndex = 3;
			this.txtO3.Text = "";
			// 
			// txtO2
			// 
			this.txtO2.Location = new System.Drawing.Point(224, 24);
			this.txtO2.Name = "txtO2";
			this.txtO2.ReadOnly = true;
			this.txtO2.Size = new System.Drawing.Size(96, 22);
			this.txtO2.TabIndex = 2;
			this.txtO2.Text = "";
			// 
			// txtO1
			// 
			this.txtO1.Location = new System.Drawing.Point(112, 24);
			this.txtO1.Name = "txtO1";
			this.txtO1.ReadOnly = true;
			this.txtO1.Size = new System.Drawing.Size(96, 22);
			this.txtO1.TabIndex = 1;
			this.txtO1.Text = "";
			// 
			// txtNghiemPTB1
			// 
			this.txtNghiemPTB1.BackColor = System.Drawing.Color.Yellow;
			this.txtNghiemPTB1.Location = new System.Drawing.Point(24, 24);
			this.txtNghiemPTB1.Name = "txtNghiemPTB1";
			this.txtNghiemPTB1.ReadOnly = true;
			this.txtNghiemPTB1.Size = new System.Drawing.Size(56, 22);
			this.txtNghiemPTB1.TabIndex = 0;
			this.txtNghiemPTB1.Text = "";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(584, 72);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Hướng dẫn";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(568, 40);
			this.label1.TabIndex = 0;
			this.label1.Text = "Các bạn hãy điền phương trình bậc 2 vào 3 ô trống bên trên và điền vào 2 ô trống " +
				"bên dưới phương trình bậc 1. Mình đã sử dụng Synthetic Division để lập trình giả" +
				"i bài toán này!";
			// 
			// ChiaPhuongTrinhBac2ChoPhuongTrinhBac1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(602, 456);
			this.Controls.Add(this.groupBox4);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "ChiaPhuongTrinhBac2ChoPhuongTrinhBac1";
			this.Text = "Chia Phuong Trinh Bac 2 Cho Phuong Trinh Bac 1";
			this.groupBox4.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox5.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion



		// Chia phương trình bậc 2 cho phương trình bậc 1
		private void btnChia_Click(object sender, System.EventArgs e)
		{
			if (txtA.Text == "")
			{
				MessageBox.Show("Bạn hãy điền vào ô trống giá trị A!");
			}
			else if (txtB.Text == "")
			{
				MessageBox.Show("Bạn hãy điền vào ô trống giá trị B!");
			}
			else if (txtC.Text == "")
			{
				MessageBox.Show("Bạn hãy điền vào ô trống giá trị C!");
			}
			else if (txtAA.Text == "")
			{
				MessageBox.Show("Bạn hãy điền vào ô trống giá trị AA!");
			}
			else if (txtBB.Text == "")
			{
				MessageBox.Show("Bạn hãy điền vào ô trống giá trị BB!");
			}
			else
			{
				try
				{
					double dblGiaTriA = Convert.ToDouble(txtA.Text);
					double dblGiaTriB = Convert.ToDouble(txtB.Text);
					double dblGiaTriC = Convert.ToDouble(txtC.Text);
					double dblGiaTriAA = Convert.ToDouble(txtAA.Text);
					double dblGiaTriBB = Convert.ToDouble(txtBB.Text);

					double dblNghiemPTB1 = -dblGiaTriBB/dblGiaTriAA;
					txtNghiemPTB1.Text = dblNghiemPTB1.ToString();
					txtO1.Text = dblGiaTriA.ToString();
					txtO2.Text = dblGiaTriB.ToString();
					txtO3.Text = dblGiaTriC.ToString();

					txtO6.Text = dblGiaTriA.ToString();
					double dblO4 = dblNghiemPTB1 * dblGiaTriA;
					txtO4.Text = dblO4.ToString();
					double dblO7 = dblGiaTriB + dblO4;
					txtO7.Text = dblO7.ToString();
					double dblO5 = dblNghiemPTB1 * dblO7;
					txtO5.Text = dblO5.ToString();
					double dblO8 = dblGiaTriC + dblO5;
					txtO8.Text = dblO8.ToString();


					if (dblO8 == 0)
					{
						txtKetQua.Text = dblGiaTriA.ToString() + "x + " + dblO7.ToString();
					}
					else
					{
						txtKetQua.Text = "(" + dblGiaTriA.ToString() + "x + " + dblO7.ToString() + ") dư " + dblO8.ToString();
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show("Đã có lỗi xảy ra! Bạn hãy kiểm tra lại xem mình đã thao tác đúng chưa nhé!", ex.Source);
				}
			}
		}
	}
}
